// CommonTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "../include/Type.h"
#include "../include/3rd_part/xml/tinyxml.h"

int _tmain(int argc, _TCHAR* argv[])
{

    TiXmlDocument doc;
	if( !doc.LoadFile( "D:\\development\\exercise\\Common\\CommonTest\\TestData\\00000000o.chunk") )
	{
		assert( false );
	}
	/* first
	TiXmlHandle docHandle( &doc );
	TiXmlElement* pRoot = doc.RootElement();
	std::cout << "	Chunk Name: " << pRoot->Value() << std::endl;

	TiXmlNode* pChild = pRoot->FirstChild();
	while( pChild != NULL )
	{
		std::cout << "			Chunk Item Name: " << pChild->Value() << std::endl;
		pChild = pRoot->IterateChildren(pChild);
	}
	*/

	//second
	TiXmlHandle docHandle( &doc );
	TiXmlHandle ptrRoot = docHandle.FirstChildElement();
	
	std::cout << "	Chunk Name: " << ptrRoot.ToElement()->Attribute("Id") << std::endl;

	int i = 0;
	while( true )
	{
		if( !docHandle.FirstChild().ChildElement(i).ToElement() )
			break;

		std::cout << "			Chunk Item Name: " << docHandle.FirstChild().ChildElement(i).ToElement()->Value() << std::endl;

		i++;
	}

	TiXmlElement* pChunkNode = ptrRoot.Child("Chunk",0).ToElement();
	
	TiXmlNode* pNormal = pChunkNode->InsertEndChild( TiXmlText("normal") );
	assert( pNormal != NULL );
	if( pChunkNode->FirstChild("normal") == NULL )
		assert(false);

	String strNormal = pChunkNode->FirstChild("normal")->ToText()->Value();



	//String strNormal = pNormal->ToElement()->GetText();


	::system( "pause" );

	return 0;
}

